<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

<!--
  PubSub 包含n个方法的对象
  1. subcribe(msgName, callback): 订阅消息
  2. publish(msgName, data): 发布异步的消息
  3. publishSync(msgName, data):  发布同步的消息
  4. unsubscribe(flag): 取消消息订阅
-->
<script src="../lib/JustMicrobundle.umd.js"></script>
<script>
    const {PubSub} = JustMicrobundle
    // 订阅消息
    PubSub.subscribe('add', (data) => {
        console.log('add()...', data)
    })
    PubSub.subscribe('add', (data) => {
        console.log('add2()...', data)
    })
    const token = PubSub.subscribe('add', (data) => {
        console.log('add3()...', data)
    })
    PubSub.subscribe('update', (data) => {
        console.log('update()...', data)
    })

    // PubSub.unsubscribe(token)
    // PubSub.unsubscribe('add')
    // PubSub.unsubscribe()

    PubSub.publish('add', 12)
    PubSub.publish('update', 13)
    console.log('----')
    // PubSub.unsubscribe(token)
    // PubSub.unsubscribe('add')

</script>

</body>
</html>
